<div class="SipeiMain_r fr">
    <h2 class="clearfix fonts_18 height45 fontc_444"><?php echo $this->title; ?></h2>
    <div class="clearfix back_bgf border_3 border_c pr30 pt20 pb20 height32 fontc_666">
        <form class="clearfix pb10" action="<?php echo $this->createUrl('/task/default/index')?>" method="GET" >
            <table with="100%">
                <tbody>
                    <tr>
                        <td width="134" align="right" class="pt10 pr2">所属考试项目：</td>
                        <td width="250" class="pt10">
                            <span class="fl standard_select pt5 pr7 pb5 pl3 border_c border_3">
                                <span class="fl select_shelter">
                                    <select class="fl fontc_666" name="exam_id">
                                        <option value="0">请选择</option>
                                        <?php if ($exam): foreach ($exam as $one): ?>
                                                <option value="<?php echo $one['exam_id']; ?>" <?php
                                                if ($one['exam_id'] == $serch['exam_id']) {
                                                	echo "selected";
                                                }
                                                ?>><?php echo $one['exam_term_name']; ?></option>
                                                        <?php
                                                        endforeach;
                                                        endif;
                                                ?>
                                    </select>
                                </span>
                            </span>
                        </td>
                        <td align="right" class="pt10 pr2">角色：</td>
                        <td class="pt10">
                            <span class="fl standard_select pt5 pr7 pb5 pl3 border_c border_3">
                                <span class="fl select_shelter select_shelter2">
                                    <select class="fl fontc_666" name="role_id">
                                        <option value="0">请选择</option>
                                        <?php if ($role): foreach ($role as $one): ?>
                                                <option value="<?php echo $one['role_id']; ?>" <?php
                                                if($one['role_id']==$serch['role_id']){
                                                	echo "selected";
                                                }
                                                ?>><?php echo $one['role_name']; ?></option>
                                                        <?php
                                                        endforeach;
                                                        endif;
                                                ?>
                                    </select>
                                </span>
                            </span>
                        </td>

                        <td width="126" align="right" class="pt10"><input type="submit" value="查询" class="cursor b_a_n border_3 back_bgfb w80 height32 fontc_FFF fonts_12" /></td>
                    </tr>
                    <tr>
                        <td align="right" class="pt10 pr2">截止日期：</td>
                        <td class="pt10">
                            <input type="text" value="<?php echo $serch['task_expired'] ?>" name='task_expired' class="w140 pt5 pr5 pb5 pl10 height20 border_c border_3 fontc_666 SipeiTime" onfocus="WdatePicker()" />
                        </td>
                        <td width="103" align="right" class="pt10 pr2">责任人：</td>
                        <td width="151" class="pt10">
                            <span class="fl standard_select pt5 pr7 pb5 pl3 border_c border_3">
                                <span class="fl select_shelter select_shelter2">
                                    <select class="fl fontc_666" name="user_id">
                                        <option value="0">请选择</option>
                                        <?php if ($user): foreach ($user as $one): ?>
                                                <option value="<?php echo $one['id']; ?>" <?php
                                                if ($one['id'] == $serch['user_id']) {
                                                	echo "selected";
                                                }
                                                ?> ><?php echo $one['username']; ?></option>
                                                        <?php
                                                        endforeach;
                                                        endif;
                                                ?>
                                    </select>
                                </span>
                            </span>
                        </td>

                    </tr>
                    <tr>
                        <td align="right" class="pt10 pr2">任务状态：</td>
                        <td class="pt10">
                            <span class="fl standard_select pt5 pr7 pb5 pl3 border_c border_3">
                                <span class="fl select_shelter select_shelter2">
                                    <select class="fl fontc_666" name="task_status">
                                        <option value="0">请选择</option>
                                        <option value="1" <?php
                                        if (1 == $serch['task_status']) {
                                        	echo "selected";
                                        }
                                        ?>>完成</option>
                                        <option value="2" <?php
                                        if (2 == $serch['task_status']) {
                                        	echo "selected";
                                        }
                                        ?>>未完成</option>
                                    </select>
                                </span>
                            </span>
                        </td>
                    </tr>
                </tbody>
            </table>
        </form>
    </div>
    <div class="clearfix back_bgf border_c mt15 pt20 pb20">
        <div class="clearfix pb20 pl30">
                <?php if($role_id==1):?>
        	<input type="button" onclick="taskadd()" value="新增" style="margin-right:30px;" class="cursor fr b_a_n border_3 back_bgfb w80 height32 fontc_FFF fonts_12" />
        	<?php endif;?>
                <input type="button" value="删除" onclick="delete_all()" class="fl b_a_n border_3 back_bgfb w80 height32 fontc_FFF fonts_12 cursor" />
        </div>
        <form>
            <table class="height40" width="100%">
                <thead class="back_bgf5 fontc_666">
                    <tr>
                    	<th width="40" align="right" class="m_hr_t m_hr_b pr10"><input type="checkbox" class="checkboxs"></th>
                        <th width="100" align="center" class="m_hr_t m_hr_b pr10">责任人</th>
                        <th width="200" align="center" class="m_hr_t m_hr_b">考试项目</th>
                        <th width="180" align="left" class="m_hr_t m_hr_b">任务描述</th>
                        <th width="80" align="center" class="m_hr_t m_hr_b">状态</th>
                        <th width="80" align="center" class="m_hr_t m_hr_b">截止日期</th>
                        <th width="90" align="center" class="m_hr_t m_hr_b">操作</th>
                    </tr>
                </thead>
                <tbody class="fontc_444">
                    <?php if ($taskinfo): foreach ($taskinfo as $one): ?>
                            <tr>
                            	<td align="right" class="m_hr_b pr10"><?php if($user_id==$one['user_id']||$role_id==1):?><input type="checkbox" name="deleteAll[]" value="<?php echo $one['task_id'];?>" class="checkbox"><?php endif;?></td>
                                <td align="center" class="m_hr_b fontc_666 pr10"><?php echo $one['username']; ?></td>
                                <td align="center" class="m_hr_b"><?php echo $one['exam_term_name']; ?></td>
                                <td align="left" class="m_hr_b"><?php echo $one['task_name']; ?></td>
                                <td align="center" class="m_hr_b"><?php
                                switch ($one['task_status']) {
                                	case 1: echo "完成";
                                	break;
                                	case 2: echo "未完成";
                                	break;
                                }
                                    ?></td>
                                <td align="center" class="m_hr_b"><?php echo date('Y-m-d', $one['task_expired']); ?></td>
                                <td align="center" class="m_hr_b">
                                    <?php if($user_id==$one['user_id']||$role_id==1):?>
                                    <a onclick="edittask(<?php echo $one['task_id']; ?>)" class="mr10 cursor"><img src="/themes/default/images/Sipei/edit.png" title="编辑" /></a>
                                    <a onclick="deletetask(<?php echo $one['task_id']; ?>, $(this))" class="cursor"><img src="/themes/default/images/Sipei/delate.png" title="删除" /></a>
                                    <?php endif;?>
                                </td>
                            </tr>
                            <?php
                            endforeach;
                            else:
                        ?>
                        <tr>
                            <td colspan='7' align="center" class="pl30">暂无数据!</td>
                        </tr>
                    <?php endif; ?>
                </tbody>
            </table>
        </form>
        <?php $this->renderPartial('//partial/partial_pager', array('pages' => $pages, "url" => $pageUrl)); ?>
    </div>
</div>

<script type="text/javascript" >
var api;
function taskadd()
{
	api = $.dialog({
		id: 'testID2',
		lock: true,
		fixed: true,
		title: "新增",
		width: 500,
		height: 350,
		max: false,
		min: false
	});
	$.get('/task/default/taskadd', function(data) {
		api.content(data);
	});
}
function deletetask(id, $this) {
	$.dialog.confirm('确定删除吗', function() {
		$.get('/task/default/deletetask', {task_id: id}, function(data) {
			if (data == 1) {
				$this.parents("tr").remove();
			} else {
				alert("删除失败");
			}
		});
	});
}

function delete_all(){
	var aa='';
	$("input[name='deleteAll[]']:checkbox:checked").each(function(){
		aa+=$(this).val()+',';
	});
	if(aa == ''){
		$.dialog.alert("请选择要删除条目");
		return false;
	}
	$.dialog.confirm('确定删除所选数据吗', function() {
		aa+=0;

		$.get('/task/default/delete_all', {id: aa}, function(data) {
			location.reload();

		});
	});
}
function edittask(id)
{
	api = $.dialog({
		id: 'testID2',
		lock: true,
		fixed: true,
		title: "编辑",
		width: 500,
		height: 400,
		max: false,
		min: false
	});
	$.get('/task/default/taskedit', {task_id: id}, function(data) {
		api.content(data);
	});
}
$(function() {
	$(".checkboxs").click(function() {
		var checkedS = $(this).attr("checked");
		if (checkedS) {
			$(".checkbox").attr("checked", true)
		} else {
			$(".checkbox").removeAttr("checked")
		}
	})

})
</script>